package api

import (

	"server/global"
    "server/model/common/response"
    "server/plugin/mall/model"
    "server/plugin/mall/model/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "server/utils"
)

var A商品1 = new(shangpin1)

type shangpin1 struct {}

// CreateA商品1 创建商品1
// @Tags A商品1
// @Summary 创建商品1
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A商品1 true "创建商品1"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /shangpin1/createA商品1 [post]
func (a *shangpin1) CreateA商品1(c *gin.Context) {
	var info model.A商品1
	err := c.ShouldBindJSON(&info)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    info.CreatedBy = utils.GetUserID(c)
	err = serviceA商品1.CreateA商品1(&info)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteA商品1 删除商品1
// @Tags A商品1
// @Summary 删除商品1
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A商品1 true "删除商品1"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /shangpin1/deleteA商品1 [delete]
func (a *shangpin1) DeleteA商品1(c *gin.Context) {
	ID := c.Query("ID")
    userID := utils.GetUserID(c)
	err := serviceA商品1.DeleteA商品1(ID,userID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("删除成功", c)
}

// DeleteA商品1ByIds 批量删除商品1
// @Tags A商品1
// @Summary 批量删除商品1
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /shangpin1/deleteA商品1ByIds [delete]
func (a *shangpin1) DeleteA商品1ByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
    userID := utils.GetUserID(c)
	err := serviceA商品1.DeleteA商品1ByIds(IDs,userID)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("批量删除成功", c)
}

// UpdateA商品1 更新商品1
// @Tags A商品1
// @Summary 更新商品1
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A商品1 true "更新商品1"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /shangpin1/updateA商品1 [put]
func (a *shangpin1) UpdateA商品1(c *gin.Context) {
	var info model.A商品1
	err := c.ShouldBindJSON(&info)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    info.UpdatedBy = utils.GetUserID(c)
	err = serviceA商品1.UpdateA商品1(info)
    if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("更新成功", c)
}

// FindA商品1 用id查询商品1
// @Tags A商品1
// @Summary 用id查询商品1
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query model.A商品1 true "用id查询商品1"
// @Success 200 {object} response.Response{data=model.A商品1,msg=string} "查询成功"
// @Router /shangpin1/findA商品1 [get]
func (a *shangpin1) FindA商品1(c *gin.Context) {
	ID := c.Query("ID")
	reshangpin1, err := serviceA商品1.GetA商品1(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
    response.OkWithData(reshangpin1, c)
}

// GetA商品1List 分页获取商品1列表
// @Tags A商品1
// @Summary 分页获取商品1列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.A商品1Search true "分页获取商品1列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /shangpin1/getA商品1List [get]
func (a *shangpin1) GetA商品1List(c *gin.Context) {
	var pageInfo request.A商品1Search
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := serviceA商品1.GetA商品1InfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}
// GetA商品1DataSource 获取A商品1的数据源
// @Tags A商品1
// @Summary 获取A商品1的数据源
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "查询成功"
// @Router /shangpin1/getA商品1DataSource [get]
func (a *shangpin1) GetA商品1DataSource(c *gin.Context) {
    // 此接口为获取数据源定义的数据
   dataSource, err := serviceA商品1.GetA商品1DataSource()
   if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
        response.FailWithMessage("查询失败:" + err.Error(), c)
		return
   }
    response.OkWithData(dataSource, c)
}
// GetA商品1Public 不需要鉴权的商品1接口
// @Tags A商品1
// @Summary 不需要鉴权的商品1接口
// @accept application/json
// @Produce application/json
// @Param data query request.A商品1Search true "分页获取商品1列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /shangpin1/getA商品1Public [get]
func (a *shangpin1) GetA商品1Public(c *gin.Context) {
    // 此接口不需要鉴权 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    serviceA商品1.GetA商品1Public()
    response.OkWithDetailed(gin.H{"info": "不需要鉴权的商品1接口信息"}, "获取成功", c)
}
